package com.lancoo.ccas52.controller;

import com.lancoo.ccas52.pojo.response.score.CourseLink;
import com.lancoo.ccas52.pojo.vo.CourseTypeDto;
import com.lancoo.ccas52.service.ExternalService;
import com.lancoo.ccas52.util.EnumResultCode;
import com.lancoo.ccas52.util.MD5Util;
import com.lancoo.ccas52.util.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ExternalController
 * @Description TODO
 * @Author quin
 * @Date 2023/5/19 10:41
 */
@Api(tags = "对外接口")
@RestController
@RequestMapping("/api/external")
public class ExternalController {

    @Resource
    private ExternalService externalService;

    @ApiOperation("获取发布的课程环节")
    @GetMapping(value = "/getCourseLink")
    public ResponseObject<List<CourseLink>> getCourseLink(@ApiParam(value = "发起请求的子系统ID", required = true) @RequestHeader String appId,
                                                          @ApiParam(value = "对appid参数的值取MD5值并反序", required = true) @RequestHeader String accessToken,
                                                          @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                          @ApiParam(value = "学期id", required = true) @RequestParam String term) {
        //校验appId和accessToken
        if (!MD5Util.reverseSequenceCheck(appId, accessToken)) {
            return ResponseObject.ofFail(EnumResultCode.INVALID_TOKEN);
        }
        return ResponseObject.ofSuccess(externalService.getCourseLink(schoolId, term));
    }
}
